package com.sk.app;
import org.json.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class DataInput extends Activity{
	private Button no_string,has_string;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.data_input);
		no_string = (Button)findViewById(R.id.no_string);
		has_string = (Button)findViewById(R.id.has_string);
		no_string.setOnClickListener(new btn_click());
		has_string.setOnClickListener(new btn_click());
	}
	protected class btn_click implements OnClickListener {
		@Override
		public void onClick(View v) {
			TextView textView1 = (TextView)findViewById(R.id.get_data);
			switch (v.getId()) {
			case R.id.no_string:
				String Url1 = "http://192.168.0.104/GZOPWaterWebService/WebServiceTest1.asmx/getPeopleList";
				try {
					HttpPost request = new HttpPost(Url1);
					request.addHeader("Content-Type", "application/json; charset=utf-8");
					HttpResponse httpResponse = new DefaultHttpClient().execute(request);
					if(httpResponse.getStatusLine().getStatusCode()!=404){
						String result = EntityUtils.toString(httpResponse.getEntity());
						Toast.makeText(DataInput.this, result, Toast.LENGTH_LONG).show();
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
				
				
				/*
				String Url1="http://192.168.200.102/service/WebService1.asmx/GetPeople";
				try {
					HttpPost request= new HttpPost(Url1);
					request.addHeader("Content-Type", "application/json; charset=utf-8");
			        HttpResponse httpResponse = new DefaultHttpClient().execute(request);        
			        if(httpResponse.getStatusLine().getStatusCode()!=404){			        	
			        	String result = EntityUtils.toString(httpResponse.getEntity());			       			        	
			        	JSONObject jsonObject = new JSONObject(result).getJSONObject("d");
			        	Log.v("jsonObject", jsonObject.toString());
			        	Log.v("Nmae", jsonObject.getString("Name"));
			        	JSONObject tempObject = jsonObject.getJSONObject("student");
			        	Log.v("tempObject", tempObject.toString());
			        	Log.v("Name", tempObject.getString("Name"));
			        }
				} catch (Exception e) {
					e.printStackTrace();
				}
				*/				
				break;
			case R.id.has_string:
				String Url2="http://192.168.200.50/service/WebService1.asmx/GetPeople";
				try {
					HttpPost request = new HttpPost(Url2);
//					request.addHeader("Content-Type", "application/json; charset=utf-8");
					HttpResponse httpResponse = new DefaultHttpClient().execute(request);
					if(httpResponse.getStatusLine().getStatusCode()!=404){
						String result = EntityUtils.toString(httpResponse.getEntity());
						Toast.makeText(DataInput.this, result, Toast.LENGTH_LONG).show();
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
				break;
			}			
		}
	}
}